package com.fowo.api.user.service.impl;

import com.fowo.api.user.model.JwtUserInfo;
import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.TreeMap;

/**
 * 积木报表鉴权
 */
@Component
public class JimuReportTokenService implements JmReportTokenServiceI {

    @Override
    public String getUsername(String s) {
        JwtUserInfo from = JwtUserInfo.from(s);
        if (from != null) {
            return from.getUsername();
        }
        return null;
    }

    @Override
    public String[] getRoles(String s) {
        return new String[0];
    }

    @Override
    public Boolean verifyToken(String s) {
        return JwtUserInfo.checkToken(s);
    }

    @Override
    public Map<String, Object> getUserInfo(String token) {
        JwtUserInfo from = JwtUserInfo.from(token);
        if (from != null) {
            Map<String, Object> map = new TreeMap<>();
            map.put("sysUserCode", from.getUserId());
            map.put("sysUserName", from.getUsername());
            map.put("sysUserType", from.getType());
            return map;
        }
        return null;
    }
}
